package com.kookapi.asserts.impl;

import com.kookapi.asserts.AssertionComponent;
import com.kookapi.asserts.result.AssertionResult;
import io.restassured.response.Response;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @author bairimengchang
 * @version 1.0
 * @project kookapi
 * @description 商品限购断言逻辑
 * @date 2025/10/11
 */
@Component("productLimitAssertionComponent")
@Slf4j
public class ProductLimitAssertionComponent implements AssertionComponent {
    @Override
    public AssertionResult execute(Response response, Map<String, Object> context) {

        // 1、从上下文中取出提示信息
        String buyLimitRuleHint = (String) context.get("buyLimitRuleHint");
        // 2、判断下内容是否为“剩余可购：0”
        if ("剩余可购：0".equals(buyLimitRuleHint)) {
            return AssertionResult.success("商品限购校验成功");
        }
        return AssertionResult.failure("商品限购校验失败");
    }
}
